package leetcode;

public class LC30 {
    public static void main(String[] args) {
        LC30 lc30 = new LC30();
        ListNode.print(lc30.swapPairs(ListNode.ln(new int[]{1,2,3,4})));
        ListNode.print(lc30.swapPairs(ListNode.ln(new int[]{1})));
        ListNode.print(lc30.swapPairs(ListNode.ln(new int[]{})));
    }
    public ListNode swapPairs(ListNode head) {
        ListNode ans = new ListNode(0,head);
        ListNode temp = ans;
        while (true){
            ListNode x = temp.next;
            if (x == null) break;
            ListNode y = x.next;
            if (y == null) break;
            temp.next = y;
            x.next = y.next;
            y.next = x;
            temp = x;
        }
        return ans.next;
    }
}
